<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>系统后台 - {$Think.config.INTENDANT_NAME} - by HemaCMS</title>
    <link href="__INTENDANT__/css/admin_style.css" rel="stylesheet" />
    <script src="__COMMON__/jquery.js"></script>
    <script src="__COMMON__/jquery.cookie.js"></script>

    <link href="__COMMON__/zTree/css/zTreeStyle/zTreeStyle.css"  rel="stylesheet" />
    <script src="__COMMON__/zTree/js/jquery.ztree.core-3.5.min.js"></script>
    <script src="__COMMON__/zTree/js/jquery.ztree.excheck-3.5.min.js"></script>
    <script src="__COMMON__/layer/layer.js"></script>
    <script src="__INTENDANT__/js/iteny.intendant.js"></script> <!-- 公共easyui JS -->
	<link href="__INTENDANT__/css/icons.css" rel="stylesheet" />
    <link href="__INTENDANT__/css/iteny.css" rel="stylesheet" />

	<style type="text/css">
	.table_full{background: #fafafa url(__INTENDANT__/images/hr.png) 0 bottom repeat-x;margin-bottom: 0;padding: 10px;}
	.tree-icon{
		display: inline-block;
		width: 16px;
		height: 16px;
		vertical-align: top;
		overflow: hidden;
	}
	.ztree li span.button{margin: 3px;}
	</style>

</head>
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
	<div class="nav">
	    <ul class="cc">
	        <li><a href="{:U('Site/role')}">角色管理</a></li>
	        <li><a href="{:U('Site/addRole')}">添加角色</a></li>
	    </ul>
	</div>
	<div class="table_list">
		<div class="h_a">{$name} - 角色授权</div>
	  	<form class="J_ajaxFsorm" action="{:U('Site/setRole')}" method="post">
		    <div class="table_full">
		      <ul id="treeDemo" class="ztree">
		      </ul>
		    </div>
		    <div class="btn_wrap">
		      <div class="btn_wrap_pd">
		      	<input type="hidden" name="setRole" value="setRole" />
		        <input type="hidden" name="id" value="{$id}" />
		        <input type="hidden" name="menuid" value="" />
		        <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">授权</button>
		      </div>
		    </div>
	  	</form>
  	</div>
</div>
<script type="text/javascript">
//配置
var setting = {
	check: {
		enable: true,
		chkboxType:{ "Y" : "ps", "N" : "ps" }
	},
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "pid",
        }
    },
    callback: {
        beforeClick: function (treeId, treeNode) {
            if (treeNode.isParent) {
                zTree.expandNode(treeNode);
                return false;
            } else {
                return true;
            }
        },
		onClick:function(event, treeId, treeNode){
			//栏目ID
			var catid = treeNode.catid;
			//保存当前点击的栏目ID
			setCookie('tree_catid',catid,1);
		}
    }
};
//节点数据
var zNodes ={$json};
//zTree对象
// var zTree = null;
// Wind.css('zTree');
$(function(){
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			// setCheck();
		// 	$("#py").bind("change", setCheck);
		// 	$("#sy").bind("change", setCheck);
		// 	$("#pn").bind("change", setCheck);
		// 	$("#sn").bind("change", setCheck);
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.expandAll(true);
	// });
	$('button.J_ajax_submit_btn').on('click', function (e) {
		e.preventDefault();
		var btn = $(this),
        form = btn.parents('form.J_ajaxFsorm');
        if(btn.attr("disabledSubmit")){
	        btn.text('请勿重复提交...').prop('disabled', true).addClass('disabled');
	        return false;
	    }
		btn.attr("disabledSubmit",true);

  		form.find('input[name="menuid"]').val("");
			var  nodes = zTree.getCheckedNodes(true);
			var str = "";
			$.each(nodes,function(i,value){
				if (str != "") {
					str += ",";
				}
				str += value.id;
			});
			form.find('input[name="menuid"]').val(str);
  		// var  nodes = zTree.getCheckedNodes(true);
  		// alert(str);
  		var param = form.serialize();
    	$.ajax({
			url: form.attr('action'),
			dataType:'json',
			type:'POST',
			data:param,
			beforeSend: function(){
				layer.load(1);
			},
			success: function(data){
				layer.close(layer.load(1));
				if(!data.status){
					ITENY.alert('提示信息',data.info,2,'5000');

				} else {
					ITENY.alert('提示信息',data.info,1,'5000');
					setTimeout(function(){
		                ITENY.reloadPage(window);
		            },3000);

				}
			},
			error: function(data){
				layer.close(layer.load(1));
				ITENY.alert('提示信息',data.responseText,2,'5000');

			}
		});
	});
});
</script>

</body>
</html>